#include "tcpServer.h"
 
int main(int argc,char *argv[])
{
  if (argc!=2)
  {
    printf("Using:./server port\nExample:./server 5005\n\n"); return -1;
  }

  tcpServer ts;

  ts.initServer(std::atoi(argv[1]));
  ts.acceptingConnections();
 
  std::string buffer;
  while(true) {
    if(!ts.recvMessage(buffer, 1024)) {
      std::cout << "recvMessage" << std::endl;
      break;
    }
    std::cout << "接收：" << buffer << std::endl;
  
    buffer = "0kkkkk";

    if(!ts.sendMessage(buffer)) {
      std::cout << "sendMessage" << std::endl;
      break;
    }
    std::cout << "发送：" << buffer << std::endl;
  }

  // 第6步：关闭socket，释放资源。
  close(ts.m_listenfd); 
  close(ts.m_clientfd); 
}